/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
        if(headA==nullptr || headB==nullptr)
        {
            return nullptr;
        }
        int count=0;
        ListNode* ptr=headA;
        ListNode* cur=headB;
        while(ptr !=nullptr)
        {
            cur=headB;
            while(cur!=nullptr)
            {
                if(ptr==cur)
                {
                    count=1;
                    break;
                }
                    cur=cur->next;
            }
            if(count==1)
            {
                break;
            }
            ptr=ptr->next;
        }
        return ptr;
    }
};